/**  \file Login.qml
\brief Login form / New user registration

Price My House for Nokia mobile platforms.

\author © 2011 Enrico Miglino / Tech Consulting (enrico.miglino@ovi.com)
\author "Evimin Fiyati Price My House" is protected by the copyright law
\author Distributed under the LGPL 3.0 license.
\date 2011

\par Licensing notes

    "Price My House" is free software: you can redistribute it
    and/or modify it under the terms of the Lesser GNU General Public License
    as published by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "Price My House" is distributed in the hope that it
    will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    Lesser GNU General Public License for more details.

    You should have received a copy of the Lesser GNU General Public License
    along with "Price My House".
    If not, see <http://www.gnu.org/licenses/>.

*/

import QtQuick 1.0
import com.nokia.symbian 1.0
import "../Qt-Complex" as Framework
import "PriceMyHouse.js" as Jmain
import "../Qt-Complex/Geometry.js" as Geometry

// Login form for registered users
Item {
    id: login

    width: parent.width;
    // Height is set based on the form area heigh (number or fields) and the variable
    // value of the text area.
    height: Math.round(Geometry.getFieldHeight() * 7) +  background.textHeight

    signal newuserClicked; signal loginClicked

    property string loginIntro:  ""
    property string labelUser: ""
    property string labelPassword: ""
    property string buttonLogin:  ""
    property string buttonNewUser:  ""

    // Main background recatngle with information text
    Rectangle {
        id: background
        width: parent.width
        property alias textHeight: textIntro.paintedHeight
        height: parent.height
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottom: parent.bottom
        color: "#d1cece"; border.color: "#eeeeee";
        border.width: Geometry.getFormBorder();
        radius: Geometry.getRadius()
        // Introductory text over the login area.
        Text {
            id: textIntro
            width: background.width * 0.95; anchors.top: background.top
            anchors.topMargin: 5;
            anchors.horizontalCenter: background.horizontalCenter
            color: "#ffffff"
            wrapMode: TextEdit.Wrap; font.pointSize: Geometry.getFontPoints();
            text: login.loginIntro
        }
    }
    // Background + form elements
    Rectangle {
        id: formbackground

        width: Math.round(background.width * .98);
        height: Geometry.getFieldHeight() * 6;
        anchors.bottom: background.bottom;
        anchors.bottomMargin: Geometry.getFormBorder() * 2
        anchors.horizontalCenter: background.horizontalCenter
        color: "#ffffff"; radius: Geometry.getRadius();
        border.width: Geometry.getFormBorder(); border.color: "#666666"

        // Input fields
        Column {
            id: fields
            spacing: Geometry.getFieldSpacing();
            width: formbackground.width
            anchors {
                top: formbackground.top; topMargin: Geometry.getFormBorder();
                horizontalCenter: formbackground.horizontalCenter
            }
            Text {
                id: lblUser
                wrapMode: TextEdit.NoWrap; height: Geometry.getFieldHeight()
                font.pointSize: Geometry.getFontPoints(); text: login.labelUser
            }
            InputField {
                id: fieldUser
                width: parent.width - Geometry.getFormBorder() * 2;
                height: Geometry.getFieldHeight();
            }
            Text {
                id: lblPwd
                wrapMode: TextEdit.NoWrap; height: Geometry.getFieldHeight()
                font.pointSize: Geometry.getFontPoints(); text: login.labelPassword
            }
            InputField {
                id: fieldPwd
                width: parent.width - Geometry.getFormBorder() * 2;
                height: Geometry.getFieldHeight();
                echoCharacter: TextInput.Password
            }
        }
        // Choice buttons
        Row {
            id: buttons

            spacing: Geometry.getButtonSpacing()
            width: formbackground.width - Geometry.getFormBorder() * 2

            // Anchors buttons to the bottom of the screen
            anchors {
                bottom: formbackground.bottom
                bottomMargin: Geometry.getFormBorder() * 2
                horizontalCenter: formbackground.horizontalCenter
            }

            // Send login informations for user authentication
            Framework.Loader {
                id: btnLogin

                width: (buttons.width / 2)
                height: Geometry.getButtonHeight()
                theme: "PMH";  obj: "Button";
                obj_string: login.buttonLogin
                onClicked: { login.loginClicked(); }
            }

            // load the new user creation
            Framework.Loader {
                id: btnNewUser

                width: (buttons.width / 2)
                height: Geometry.getButtonHeight()
                theme: "PMH"; obj: "Button";
                obj_string: login.buttonNewUser
                onClicked: { login.newuserClicked() }
            }
        }
    }
}
